package logic

import (
	"context"
	"errors"
	"shop_srv/model/redisinit"

	"shop_srv/internal/svc"
	"shop_srv/shop"

	"github.com/zeromicro/go-zero/core/logx"
)

type RemoveCartLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewRemoveCartLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RemoveCartLogic {
	return &RemoveCartLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 删除商品
func (l *RemoveCartLogic) RemoveCart(in *shop.RemoveCartRequest) (*shop.RemoveCartResponse, error) {
	// todo: add your logic here and delete this line

	err := redisinit.RemoveCart(int(in.UserId), int(in.ShopId))
	if err != nil {
		logx.Error("删除失败")
		return nil, errors.New("删除失败")
	}
	return &shop.RemoveCartResponse{}, nil
}
